package cn.tedu.javagame.shoot;

import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;

public class Hero {
    int x,y;
    int life,magic,score,gold;
    int fire=1;
    Image heroImg;
    Image[] heroImgs = new Image[10];
    int index = 0;
    public Hero(){
        this.x = 200;
        this.y = 500;
        this.life = 100;
        this.magic = 100;
        this.score = 0;
        this.gold = 0;
        this.heroImg = new ImageIcon("plane/ws00.png").getImage();
        for(int i=0;i<heroImgs.length;i++){
            heroImgs[i] = new ImageIcon("plane/ws0"+i+".png").getImage();
        }
    }
    public void move(int x,int y){
        this.x = x-heroImg.getWidth(null)/2;
        this.y = y-heroImg.getHeight(null)/2;
    }
    //动态效果
    public void step(){
        index ++;
        if(index == Integer.MAX_VALUE){index = 0;}
        heroImg = heroImgs[index/10%heroImgs.length];
    }
    //发射子弹
    public List<Bullet> shoot(){
        List<Bullet> bullets = new ArrayList<>();
        if(fire==1){
            int x =  this.x + heroImg.getWidth(null)/2;
            int y =  this.y;
            Bullet bullet = new Bullet(x,y);
            bullets.add(bullet);
        }else if(fire==2){
            int x1 = this.x + heroImg.getWidth(null)/3*2;
            int x2 = this.x + heroImg.getWidth(null)/3;
            int y = this.y;
            Bullet bullet1 = new Bullet(x1,y);
            Bullet bullet2 = new Bullet(x2,y);
            bullets.add(bullet1);
            bullets.add(bullet2);
        }else if(fire==3){
            int x1 = this.x + heroImg.getWidth(null)/4;
            int x2 = this.x + heroImg.getWidth(null)/2;
            int x3 = this.x + heroImg.getWidth(null)/4*3;
            int y = this.y;
            Bullet bullet1 = new Bullet(x1,y);
            Bullet bullet2 = new Bullet(x2,y);
            Bullet bullet3 = new Bullet(x3,y);
            bullets.add(bullet1);
            bullets.add(bullet2);
            bullets.add(bullet3);
        }
        return bullets;
    }
    //撞击掉血
    public void hitEnemy(Enemy enemy){

    }
    //拾取红心奖励
    public void hitHeart(Heart heart){

    }
}
